package com.gitee.feizns.itrip.personal.beans.dto;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 * @author feizns
 * @since 2018/12/26 0026
 */
@Data
@Accessors(chain = true)
public class Dto<T> {

    /**
     * 没有错误的 errorCode
     */
    public static final String NO_ERROR = "0";

    /**
     * 执行成功
     */
    public static final String SUCCESS = "true";

    /**
     * 执行失败
     */
    public static final String FAIL = "false";

    /**
     * 错误编号
     */
    private String errorCode;

    /**
     * 消息
     */
    private String msg;

    /**
     * 是否成功
     */
    private String success;

    /**
     * 数据
     */
    private T data;

    public Dto() {}

    public Dto(String success) {
        this.success = success;
    }

    public static <T> Dto<T> getSuccessDto(String msg, T data) {
        return new Dto<T>(SUCCESS).setErrorCode(NO_ERROR).setMsg(msg).setData(data);
    }

    public static <T> Dto<T> getSuccessDto(String msg) {
        return new Dto<T>(SUCCESS).setErrorCode(NO_ERROR).setMsg(msg);
    }

    public static <T> Dto<T> getSuccessDto() {
        return new Dto<T>(SUCCESS).setErrorCode(NO_ERROR);
    }

    public static <T> Dto<T> getFailDto(String errorCode, String msg) {
        return new Dto<T>(FAIL).setErrorCode(errorCode).setMsg(msg);
    }

    public static <T> Dto<T> getFailDto(String msg) {
        return new Dto().setErrorCode(NO_ERROR).setSuccess(FAIL).setMsg(msg);
    }

}
